package com.sky.controller.user;

import com.sky.constant.MessageConstant;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderDetailsVO;
import com.sky.vo.OrderPageVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/user/order")
@Api("订单相关接口")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    @PostMapping("submit")
    @ApiOperation("用户下单")
    public Result addOrder(@RequestBody OrdersSubmitDTO submitDTO) throws IOException {
        OrderSubmitVO submitVO = ordersService.addOrder(submitDTO);
        return Result.success(submitVO);
    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("用户订单详情")
    public Result QueryOrderDetail(@PathVariable Long id){
         OrderDetailsVO orderDetailsVO = ordersService.selectById(id);
        return Result.success(orderDetailsVO);
    }

    @GetMapping("/historyOrders")
    @ApiOperation("历史订单查询")
    public Result QueryHistoryOrderDetail(@RequestParam(defaultValue = "1") Integer page
                                            ,@RequestParam(defaultValue = "10") Integer pageSize
                                            ,Integer status){

        OrderPageVO orderPageVO = ordersService.QueryHistoryOrderDetail(page,pageSize,status);
        return Result.success(orderPageVO);
    }

    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result OnceAgain(@PathVariable Long id){
        ordersService.OnceAgain(id);
        return Result.success();
    }

    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancelOrder(@PathVariable Long id){
        ordersService.cancelOrderById(id);
        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    @ApiOperation("催单")
    public Result reminderOrder(@PathVariable Long id){
        ordersService.reminderOrder(id);
        return Result.success();
    }
}